/*
 * HelloScene.fx
 *
 * Created on 03.12.2009, 12:02:44
 */

package org.zhgames.zhciv.client.gui.scenes;

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.layout.*;
import javafx.scene.text.*;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.stage.Alert;
import javafx.geometry.Rectangle2D;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.control.Label;
import javafx.animation.*;

/**
 * @author Vitaliy_Turilkin
 */

public class HelloScene extends CustomNode{
     public-init var sceneMaster:SceneMaster;

     def text:Text = Text{
         content:"ZHCIV press space key"
         visible:false
         textAlignment: TextAlignment.CENTER
         y: bind scene.height / 2
         font:Font{
             size: 40
         }
     }

     def showText:Timeline = Timeline{
        repeatCount: 1
        keyFrames: [
            KeyFrame{
                time:0s
                values: [
                    text.x => 0
                ]
                action: function(){
                    text.visible=true
                }
            }
            KeyFrame{
                time:3s
                values: [
                    text.x => scene.width / 2 - text.boundsInParent.width / 2 tween Interpolator.LINEAR
                ]
                action: function(){
                }
            }
        ]
     }

     def hideText:Timeline = Timeline{
        repeatCount: 1
        keyFrames: [
            KeyFrame{
                time:0s
                values: [
                    text.x => scene.width / 2 - text.boundsInParent.width / 2
                ]
                action: function(){
                }
            }
            KeyFrame{
                time:3s
                values: [
                    text.x => scene.width tween Interpolator.LINEAR
                ]
                action: function(){
                    sceneMaster.showMenu();
                }
            }
        ]
     }

    override function create():Node {
         def group = Group{
             focusTraversable:true
             content:[
                     text
                     ]
             onKeyPressed: function( e: KeyEvent ):Void {
                if(e.code == KeyCode.VK_SPACE){
                    hideText.play();
                }
             }
         };
         showText.play();
         return group;
     }
}
